package com.example.a2007dou_shop.fragment

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.a2007dou_shop.entity.LoveEntity
import com.example.a2007dou_shop.entity.VideoEntityResult
import com.example.a2007dou_shop.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class VideoViewModel:BaseViewModel() {
    val videoSuccess = MutableLiveData<VideoEntityResult>()
    val videoFail = MutableLiveData<String>()

    fun getvideo(order:String,page:Int,size:Int){
        viewModelScope.launch {
            try {
                val result = apiServer.getvideo(order, page, size)
                videoSuccess.value = result
            }catch (e:Exception){
                videoFail.value = e.message
            }
        }
    }

    val loveSuccess = MutableLiveData<LoveEntity>()
    val loveFail = MutableLiveData<String>()
    fun love(vid:Int){
        viewModelScope.launch {
            try {
                val result = apiServer.love(vid)
                loveSuccess.value = result
            }catch (e:Exception){
                loveFail.value = e.message
            }
        }
    }
}